<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>成绩查询系统</title>
    <style>
        :root {
            --primary: #0a192f;
            --accent: #00ff88;
            --text: #ccd6f6;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', sans-serif;
        }

        body {
            background: var(--primary);
            color: var(--text);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 500px;
            margin: 0 auto;
        }

        .step {
            display: none;
            padding: 20px;
            background: rgba(255,255,255,0.05);
            border-radius: 10px;
            margin-top: 20px;
            box-shadow: 0 0 15px rgba(0,255,136,0.2);
        }

        .step.active {
            display: block;
        }

        h2 {
            color: var(--accent);
            margin-bottom: 20px;
            text-align: center;
        }

        .input-group {
            margin-bottom: 15px;
        }

        input {
            width: 100%;
            padding: 12px;
            background: rgba(255,255,255,0.1);
            border: 1px solid var(--accent);
            border-radius: 5px;
            color: var(--text);
            font-size: 16px;
        }

        button {
            width: 100%;
            padding: 12px;
            background: var(--accent);
            color: var(--primary);
            border: none;
            border-radius: 5px;
            font-weight: bold;
            cursor: pointer;
            transition: opacity 0.3s;
        }

        button:hover {
            opacity: 0.8;
        }

        .semester-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 10px;
        }

        .semester-btn {
            background: rgba(255,255,255,0.1);
            padding: 15px;
            border-radius: 5px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s;
        }

        .semester-btn:hover {
            background: var(--accent);
            color: var(--primary);
        }

        .score-item {
            display: flex;
            justify-content: space-between;
            padding: 12px;
            background: rgba(255,255,255,0.05);
            margin-bottom: 10px;
            border-radius: 5px;
            cursor: pointer;
        }

        .rank-info {
            display: none;
            color: var(--accent);
            font-size: 0.9em;
        }

        .rank-info.active-rank {
            display: block;
        }

        .error {
            color: #ff5555;
            margin-top: 5px;
            display: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 身份验证步骤 -->
        <div class="step active" id="step1">
            <h2>身份验证</h2>
            <div class="input-group">
                <input type="text" id="idNumber" placeholder="请输入身份证号码">
                <div class="error" id="idError">身份证号码格式不正确</div>
            </div>
            <button onclick="verifyID()">提交</button>
        </div>

        <!-- 学期选择步骤 -->
        <div class="step" id="step2">
            <h2>选择学期</h2>
            <div class="semester-grid">
                <div class="semester-btn" onclick="selectSemester('2023-秋季')">2023-秋季</div>
                <div class="semester-btn" onclick="selectSemester('2023-春季')">2023-春季</div>
                <div class="semester-btn" onclick="selectSemester('2022-秋季')">2022-秋季</div>
                <div class="semester-btn" onclick="selectSemester('2022-春季')">2022-春季</div>
            </div>
        </div>

        <!-- 成绩展示步骤 -->
        <div class="step" id="step3">
            <h2>成绩查询结果</h2>
            <div id="studentInfo">
                <div class="score-item">
                    <span>姓名：</span>
                    <span>张三</span>
                </div>
                <div class="score-item">
                    <span>班级：</span>
                    <span>高三(1)班</span>
                </div>
            </div>
            <div id="scoreDetails"></div>
        </div>
    </div>

    <script>
        // API配置
        const API = {
            getSemester: 'http://i.fe80.cn/shubao/api/scores.html',
            getScores: 'http://i.fe80.cn/shubao/api/scores.html'
        };

        async function verifyID() {
            const idInput = document.getElementById('idNumber');
            const errorDiv = document.getElementById('idError');
            
            if (idInput.value.length !== 18 || isNaN(idInput.value)) {
                errorDiv.style.display = 'block';
                return;
            }

            try {
                const response = await fetch(API.getSemester, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        card: idInput.value,
                        test: 1
                    })
                });
                
                const data = await response.json();
                if(data.code === 1) {
                    document.getElementById('step1').classList.remove('active');
                    document.getElementById('step2').classList.add('active');
                    renderSemesters(data.issue);
                } else {
                    errorDiv.textContent = data.msg;
                    errorDiv.style.display = 'block';
                }
            } catch (error) {
                errorDiv.textContent = '网络请求失败';
                errorDiv.style.display = 'block';
            }
        }

        function renderSemesters(semesters) {
            const grid = document.querySelector('.semester-grid');
            grid.innerHTML = semesters
                .filter(s => s.open === 1)
                .map(s => `<div class="semester-btn" onclick="selectSemester('${s.issue}')">${s.issue_name}</div>`)
                .join('');
        }

        async function selectSemester(issue) {
            try {
                const response = await fetch(API.getScores, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        card: document.getElementById('idNumber').value,
                        issue: issue,
                        test: 1
                    })
                });

                const data = await response.json();
                if(data.code === 1) {
                    document.getElementById('step2').classList.remove('active');
                    document.getElementById('step3').classList.add('active');
                    renderScores(data.column);
                }
            } catch (error) {
                console.error('请求失败:', error);
            }
        }

        function renderScores(columns) {
            const infoDiv = document.getElementById('studentInfo');
            const detailsDiv = document.getElementById('scoreDetails');
            
            // 清空内容
            infoDiv.innerHTML = '';
            detailsDiv.innerHTML = '';

            columns.forEach(item => {
                const container = item.name === '姓名' || item.name === '班级' ? infoDiv : detailsDiv;
                const div = document.createElement('div');
                div.className = 'score-item';
                
                if(['总分','语文','数学','英语','物理','生物','历史','地理','道德与法治'].includes(item.name)) {
                    div.innerHTML = `
                        <span>${item.name}：</span>
                        <span>${item.value}</span>
                        ${item.tips ? `<span class="rank-info">${item.tips.join(' | ')}</span>` : ''}
                    `;
                } else {
                    div.innerHTML = `
                        <span>${item.name}：</span>
                        <span style="color: ${item.color}">${item.value}</span>
                    `;
                }
                
                container.appendChild(div);
                div.addEventListener('click', function() {
                    const rankInfo = div.querySelector('.rank-info');
                    if(rankInfo) {
                        rankInfo.classList.add('active-rank');
                        setTimeout(() => {
                            rankInfo.classList.remove('active-rank');
                        }, 3000);
                    }
                });
            });
        }
    </script>
</body>
</html>